package com.leetcode.LC;

public class LC1299 {
    public int[] replaceElements(int[] arr) {
        //从后往前遍历
        int[] ints = new int[arr.length];
        int max = -1;

        for (int i = arr.length - 1; i >= 0; i--) {
            if (i == arr.length - 1) {
                max = Math.max(max, arr[i]);
                ints[i] = -1;
            } else {
                ints[i] = max;
                max = Math.max(max, arr[i]);
            }
        }
        return ints;

    }

    public static void main(String[] args) {
        for (int i : new LC1299().replaceElements(new int[]{400})) {
            System.out.print(i+",");
        }
    }
}
